<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Threadv</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Threadv">
<meta property="og:url" content="http://yoursite.com/page/12/index.html">
<meta property="og:site_name" content="Threadv">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Threadv">
  
    <link rel="alternate" href="/atom.xml" title="Threadv" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Threadv</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Suche"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-http/http_utils" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/31/http/http_utils/" class="article-date">
  <time datetime="2018-05-31T08:19:12.000Z" itemprop="datePublished">2018-05-31</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/31/http/http_utils/">HttpUtils</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="HttpUtils"><a href="#HttpUtils" class="headerlink" title="HttpUtils"></a>HttpUtils</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HttpUtils</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * get</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doGet</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     Map&lt;String, String&gt; querys)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpGet request = <span class="keyword">new</span> HttpGet(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * post form</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> bodys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doPost</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; querys,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; bodys)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpPost request = <span class="keyword">new</span> HttpPost(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (bodys != <span class="keyword">null</span>) &#123;</span><br><span class="line">            List&lt;NameValuePair&gt; nameValuePairList = <span class="keyword">new</span> ArrayList&lt;NameValuePair&gt;();</span><br><span class="line"></span><br><span class="line">            <span class="keyword">for</span> (String key : bodys.keySet()) &#123;</span><br><span class="line">                nameValuePairList.add(<span class="keyword">new</span> BasicNameValuePair(key, bodys.get(key)));</span><br><span class="line">            &#125;</span><br><span class="line">            UrlEncodedFormEntity formEntity = <span class="keyword">new</span> UrlEncodedFormEntity(nameValuePairList, <span class="string">"utf-8"</span>);</span><br><span class="line">            formEntity.setContentType(<span class="string">"application/x-www-form-urlencoded; charset=UTF-8"</span>);</span><br><span class="line">            request.setEntity(formEntity);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Post String</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> body</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doPost</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; querys,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      String body)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpPost request = <span class="keyword">new</span> HttpPost(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (StringUtils.isNotBlank(body)) &#123;</span><br><span class="line">            request.setEntity(<span class="keyword">new</span> StringEntity(body, <span class="string">"utf-8"</span>));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Post stream</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> body</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doPost</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      Map&lt;String, String&gt; querys,</span></span></span><br><span class="line"><span class="function"><span class="params">                                      <span class="keyword">byte</span>[] body)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpPost request = <span class="keyword">new</span> HttpPost(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (body != <span class="keyword">null</span>) &#123;</span><br><span class="line">            request.setEntity(<span class="keyword">new</span> ByteArrayEntity(body));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Put String</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> body</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doPut</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     Map&lt;String, String&gt; querys,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     String body)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpPut request = <span class="keyword">new</span> HttpPut(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (StringUtils.isNotBlank(body)) &#123;</span><br><span class="line">            request.setEntity(<span class="keyword">new</span> StringEntity(body, <span class="string">"utf-8"</span>));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Put stream</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> body</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doPut</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     Map&lt;String, String&gt; querys,</span></span></span><br><span class="line"><span class="function"><span class="params">                                     <span class="keyword">byte</span>[] body)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpPut request = <span class="keyword">new</span> HttpPut(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (body != <span class="keyword">null</span>) &#123;</span><br><span class="line">            request.setEntity(<span class="keyword">new</span> ByteArrayEntity(body));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Delete</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> host</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> path</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> method</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> headers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> querys</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> HttpResponse <span class="title">doDelete</span><span class="params">(String host, String path, String method,</span></span></span><br><span class="line"><span class="function"><span class="params">                                        Map&lt;String, String&gt; headers,</span></span></span><br><span class="line"><span class="function"><span class="params">                                        Map&lt;String, String&gt; querys)</span></span></span><br><span class="line"><span class="function">            <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        HttpClient httpClient = wrapClient(host);</span><br><span class="line"></span><br><span class="line">        HttpDelete request = <span class="keyword">new</span> HttpDelete(buildUrl(host, path, querys));</span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; e : headers.entrySet()) &#123;</span><br><span class="line">            request.addHeader(e.getKey(), e.getValue());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient.execute(request);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">buildUrl</span><span class="params">(String host, String path, Map&lt;String, String&gt; querys)</span> <span class="keyword">throws</span> UnsupportedEncodingException </span>&#123;</span><br><span class="line">        StringBuilder sbUrl = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">        sbUrl.append(host);</span><br><span class="line">        <span class="keyword">if</span> (!StringUtils.isBlank(path)) &#123;</span><br><span class="line">            sbUrl.append(path);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != querys) &#123;</span><br><span class="line">            StringBuilder sbQuery = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">            <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; query : querys.entrySet()) &#123;</span><br><span class="line">                <span class="keyword">if</span> (<span class="number">0</span> &lt; sbQuery.length()) &#123;</span><br><span class="line">                    sbQuery.append(<span class="string">"&amp;"</span>);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (StringUtils.isBlank(query.getKey()) &amp;&amp; !StringUtils.isBlank(query.getValue())) &#123;</span><br><span class="line">                    sbQuery.append(query.getValue());</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (!StringUtils.isBlank(query.getKey())) &#123;</span><br><span class="line">                    sbQuery.append(query.getKey());</span><br><span class="line">                    <span class="keyword">if</span> (!StringUtils.isBlank(query.getValue())) &#123;</span><br><span class="line">                        sbQuery.append(<span class="string">"="</span>);</span><br><span class="line">                        sbQuery.append(URLEncoder.encode(query.getValue(), <span class="string">"utf-8"</span>));</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (<span class="number">0</span> &lt; sbQuery.length()) &#123;</span><br><span class="line">                sbUrl.append(<span class="string">"?"</span>).append(sbQuery);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> sbUrl.toString();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> HttpClient <span class="title">wrapClient</span><span class="params">(String host)</span> </span>&#123;</span><br><span class="line">        HttpClient httpClient = <span class="keyword">new</span> DefaultHttpClient();</span><br><span class="line">        <span class="keyword">if</span> (host.startsWith(<span class="string">"https://"</span>)) &#123;</span><br><span class="line">            sslClient(httpClient);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpClient;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">sslClient</span><span class="params">(HttpClient httpClient)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            SSLContext ctx = SSLContext.getInstance(<span class="string">"TLS"</span>);</span><br><span class="line">            X509TrustManager tm = <span class="keyword">new</span> X509TrustManager() &#123;</span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="keyword">public</span> X509Certificate[] getAcceptedIssuers() &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">checkClientTrusted</span><span class="params">(X509Certificate[] xcs, String str)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">                &#125;</span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">checkServerTrusted</span><span class="params">(X509Certificate[] xcs, String str)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            ctx.init(<span class="keyword">null</span>, <span class="keyword">new</span> TrustManager[] &#123; tm &#125;, <span class="keyword">null</span>);</span><br><span class="line">            SSLSocketFactory ssf = <span class="keyword">new</span> SSLSocketFactory(ctx);</span><br><span class="line">            ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);</span><br><span class="line">            ClientConnectionManager ccm = httpClient.getConnectionManager();</span><br><span class="line">            SchemeRegistry registry = ccm.getSchemeRegistry();</span><br><span class="line">            registry.register(<span class="keyword">new</span> Scheme(<span class="string">"https"</span>, <span class="number">443</span>, ssf));</span><br><span class="line">        &#125; <span class="keyword">catch</span> (KeyManagementException ex) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(ex);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (NoSuchAlgorithmException ex) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(ex);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/31/http/http_utils/" data-id="ckcc5iwnw0064q4uwzs5l163x" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Http/">Http</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-Map2StringUtil" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/31/Map2StringUtil/" class="article-date">
  <time datetime="2018-05-31T08:09:11.000Z" itemprop="datePublished">2018-05-31</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/31/Map2StringUtil/">Map2StringUtil</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="Map2StringUtil"><a href="#Map2StringUtil" class="headerlink" title="Map2StringUtil"></a>Map2StringUtil</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Map2StringUtil</span> </span>&#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 方法名称:transMapToString</span></span><br><span class="line"><span class="comment">     * 传入参数:map</span></span><br><span class="line"><span class="comment">     * 返回值:String 形如 username'chenziwen^password'1234</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">transMapToString</span><span class="params">(Map map)</span></span>&#123;</span><br><span class="line">        java.util.Map.Entry entry;</span><br><span class="line">        StringBuffer sb = <span class="keyword">new</span> StringBuffer();</span><br><span class="line">        <span class="keyword">for</span>(Iterator iterator = map.entrySet().iterator(); iterator.hasNext();)</span><br><span class="line">        &#123;</span><br><span class="line">            entry = (java.util.Map.Entry)iterator.next();</span><br><span class="line">            sb.append(entry.getKey().toString()).append( <span class="string">"'"</span> ).append(<span class="keyword">null</span>==entry.getValue()?<span class="string">""</span>:</span><br><span class="line">                    entry.getValue().toString()).append (iterator.hasNext() ? <span class="string">"^"</span> : <span class="string">""</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> sb.toString();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/31/Map2StringUtil/" data-id="ckcc5iwix000iq4uwmb7ny4dz" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/util/">util</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-SHA1加密" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/31/SHA1加密/" class="article-date">
  <time datetime="2018-05-31T08:09:11.000Z" itemprop="datePublished">2018-05-31</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/31/SHA1加密/">SHA1 加密</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="SHA1-加密"><a href="#SHA1-加密" class="headerlink" title="SHA1 加密"></a>SHA1 加密</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SHA1</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> <span class="keyword">int</span>[] abcde = &#123;</span><br><span class="line">            <span class="number">0x67452301</span>, <span class="number">0xefcdab89</span>, <span class="number">0x98badcfe</span>, <span class="number">0x10325476</span>, <span class="number">0xc3d2e1f0</span></span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="comment">// 摘要数据存储数组</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span>[] digestInt = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>];</span><br><span class="line">    <span class="comment">// 计算过程中的临时数据存储数组</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span>[] tmpData = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">80</span>];</span><br><span class="line">    <span class="comment">// 计算sha-1摘要</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">process_input_bytes</span><span class="params">(<span class="keyword">byte</span>[] bytedata)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// 初试化常量</span></span><br><span class="line">        System.arraycopy(abcde, <span class="number">0</span>, digestInt, <span class="number">0</span>, abcde.length);</span><br><span class="line">        <span class="comment">// 格式化输入字节数组，补10及长度数据</span></span><br><span class="line">        <span class="keyword">byte</span>[] newbyte = byteArrayFormatData(bytedata);</span><br><span class="line">        <span class="comment">// 获取数据摘要计算的数据单元个数</span></span><br><span class="line">        <span class="keyword">int</span> MCount = newbyte.length / <span class="number">64</span>;</span><br><span class="line">        <span class="comment">// 循环对每个数据单元进行摘要计算</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> pos = <span class="number">0</span>; pos &lt; MCount; pos++) &#123;</span><br><span class="line">            <span class="comment">// 将每个单元的数据转换成16个整型数据，并保存到tmpData的前16个数组元素中</span></span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; <span class="number">16</span>; j++) &#123;</span><br><span class="line">                tmpData[j] = byteArrayToInt(newbyte, (pos * <span class="number">64</span>) + (j * <span class="number">4</span>));</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 摘要计算函数</span></span><br><span class="line">            encrypt();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">20</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 格式化输入字节数组格式</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">byte</span>[] byteArrayFormatData(<span class="keyword">byte</span>[] bytedata) &#123;</span><br><span class="line">        <span class="comment">// 补0数量</span></span><br><span class="line">        <span class="keyword">int</span> zeros = <span class="number">0</span>;</span><br><span class="line">        <span class="comment">// 补位后总位数</span></span><br><span class="line">        <span class="keyword">int</span> size = <span class="number">0</span>;</span><br><span class="line">        <span class="comment">// 原始数据长度</span></span><br><span class="line">        <span class="keyword">int</span> n = bytedata.length;</span><br><span class="line">        <span class="comment">// 模64后的剩余位数</span></span><br><span class="line">        <span class="keyword">int</span> m = n % <span class="number">64</span>;</span><br><span class="line">        <span class="comment">// 计算添加0的个数以及添加10后的总长度</span></span><br><span class="line">        <span class="keyword">if</span> (m &lt; <span class="number">56</span>) &#123;</span><br><span class="line">            zeros = <span class="number">55</span> - m;</span><br><span class="line">            size = n - m + <span class="number">64</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (m == <span class="number">56</span>) &#123;</span><br><span class="line">            zeros = <span class="number">63</span>;</span><br><span class="line">            size = n + <span class="number">8</span> + <span class="number">64</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            zeros = <span class="number">63</span> - m + <span class="number">56</span>;</span><br><span class="line">            size = (n + <span class="number">64</span>) - m + <span class="number">64</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 补位后生成的新数组内容</span></span><br><span class="line">        <span class="keyword">byte</span>[] newbyte = <span class="keyword">new</span> <span class="keyword">byte</span>[size];</span><br><span class="line">        <span class="comment">// 复制数组的前面部分</span></span><br><span class="line">        System.arraycopy(bytedata, <span class="number">0</span>, newbyte, <span class="number">0</span>, n);</span><br><span class="line">        <span class="comment">// 获得数组Append数据元素的位置</span></span><br><span class="line">        <span class="keyword">int</span> l = n;</span><br><span class="line">        <span class="comment">// 补1操作</span></span><br><span class="line">        newbyte[l++] = (<span class="keyword">byte</span>) <span class="number">0x80</span>;</span><br><span class="line">        <span class="comment">// 补0操作</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; zeros; i++) &#123;</span><br><span class="line">            newbyte[l++] = (<span class="keyword">byte</span>) <span class="number">0x00</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 计算数据长度，补数据长度位共8字节，长整型</span></span><br><span class="line">        <span class="keyword">long</span> N = (<span class="keyword">long</span>) n * <span class="number">8</span>;</span><br><span class="line">        <span class="keyword">byte</span> h8 = (<span class="keyword">byte</span>) (N &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h7 = (<span class="keyword">byte</span>) ((N &gt;&gt; <span class="number">8</span>) &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h6 = (<span class="keyword">byte</span>) ((N &gt;&gt; <span class="number">16</span>) &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h5 = (<span class="keyword">byte</span>) ((N &gt;&gt; <span class="number">24</span>) &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h4 = (<span class="keyword">byte</span>) ((N &gt;&gt; <span class="number">32</span>) &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h3 = (<span class="keyword">byte</span>) ((N &gt;&gt; <span class="number">40</span>) &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h2 = (<span class="keyword">byte</span>) ((N &gt;&gt; <span class="number">48</span>) &amp; <span class="number">0xFF</span>);</span><br><span class="line">        <span class="keyword">byte</span> h1 = (<span class="keyword">byte</span>) (N &gt;&gt; <span class="number">56</span>);</span><br><span class="line">        newbyte[l++] = h1;</span><br><span class="line">        newbyte[l++] = h2;</span><br><span class="line">        newbyte[l++] = h3;</span><br><span class="line">        newbyte[l++] = h4;</span><br><span class="line">        newbyte[l++] = h5;</span><br><span class="line">        newbyte[l++] = h6;</span><br><span class="line">        newbyte[l++] = h7;</span><br><span class="line">        newbyte[l++] = h8;</span><br><span class="line">        <span class="keyword">return</span> newbyte;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">f1</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y, <span class="keyword">int</span> z)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (x &amp; y) | (~x &amp; z);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">f2</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y, <span class="keyword">int</span> z)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> x ^ y ^ z;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">f3</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y, <span class="keyword">int</span> z)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (x &amp; y) | (x &amp; z) | (y &amp; z);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">f4</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (x &lt;&lt; y) | x &gt;&gt;&gt; (<span class="number">32</span> - y);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 单元摘要计算函数</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">encrypt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">16</span>; i &lt;= <span class="number">79</span>; i++) &#123;</span><br><span class="line">            tmpData[i] = f4(tmpData[i - <span class="number">3</span>] ^ tmpData[i - <span class="number">8</span>] ^ tmpData[i - <span class="number">14</span>] ^</span><br><span class="line">                    tmpData[i - <span class="number">16</span>], <span class="number">1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span>[] tmpabcde = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i1 = <span class="number">0</span>; i1 &lt; tmpabcde.length; i1++) &#123;</span><br><span class="line">            tmpabcde[i1] = digestInt[i1];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt;= <span class="number">19</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">int</span> tmp = f4(tmpabcde[<span class="number">0</span>], <span class="number">5</span>) +</span><br><span class="line">                    f1(tmpabcde[<span class="number">1</span>], tmpabcde[<span class="number">2</span>], tmpabcde[<span class="number">3</span>]) + tmpabcde[<span class="number">4</span>] +</span><br><span class="line">                    tmpData[j] + <span class="number">0x5a827999</span>;</span><br><span class="line">            tmpabcde[<span class="number">4</span>] = tmpabcde[<span class="number">3</span>];</span><br><span class="line">            tmpabcde[<span class="number">3</span>] = tmpabcde[<span class="number">2</span>];</span><br><span class="line">            tmpabcde[<span class="number">2</span>] = f4(tmpabcde[<span class="number">1</span>], <span class="number">30</span>);</span><br><span class="line">            tmpabcde[<span class="number">1</span>] = tmpabcde[<span class="number">0</span>];</span><br><span class="line">            tmpabcde[<span class="number">0</span>] = tmp;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> k = <span class="number">20</span>; k &lt;= <span class="number">39</span>; k++) &#123;</span><br><span class="line">            <span class="keyword">int</span> tmp = f4(tmpabcde[<span class="number">0</span>], <span class="number">5</span>) +</span><br><span class="line">                    f2(tmpabcde[<span class="number">1</span>], tmpabcde[<span class="number">2</span>], tmpabcde[<span class="number">3</span>]) + tmpabcde[<span class="number">4</span>] +</span><br><span class="line">                    tmpData[k] + <span class="number">0x6ed9eba1</span>;</span><br><span class="line">            tmpabcde[<span class="number">4</span>] = tmpabcde[<span class="number">3</span>];</span><br><span class="line">            tmpabcde[<span class="number">3</span>] = tmpabcde[<span class="number">2</span>];</span><br><span class="line">            tmpabcde[<span class="number">2</span>] = f4(tmpabcde[<span class="number">1</span>], <span class="number">30</span>);</span><br><span class="line">            tmpabcde[<span class="number">1</span>] = tmpabcde[<span class="number">0</span>];</span><br><span class="line">            tmpabcde[<span class="number">0</span>] = tmp;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> l = <span class="number">40</span>; l &lt;= <span class="number">59</span>; l++) &#123;</span><br><span class="line">            <span class="keyword">int</span> tmp = f4(tmpabcde[<span class="number">0</span>], <span class="number">5</span>) +</span><br><span class="line">                    f3(tmpabcde[<span class="number">1</span>], tmpabcde[<span class="number">2</span>], tmpabcde[<span class="number">3</span>]) + tmpabcde[<span class="number">4</span>] +</span><br><span class="line">                    tmpData[l] + <span class="number">0x8f1bbcdc</span>;</span><br><span class="line">            tmpabcde[<span class="number">4</span>] = tmpabcde[<span class="number">3</span>];</span><br><span class="line">            tmpabcde[<span class="number">3</span>] = tmpabcde[<span class="number">2</span>];</span><br><span class="line">            tmpabcde[<span class="number">2</span>] = f4(tmpabcde[<span class="number">1</span>], <span class="number">30</span>);</span><br><span class="line">            tmpabcde[<span class="number">1</span>] = tmpabcde[<span class="number">0</span>];</span><br><span class="line">            tmpabcde[<span class="number">0</span>] = tmp;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> m = <span class="number">60</span>; m &lt;= <span class="number">79</span>; m++) &#123;</span><br><span class="line">            <span class="keyword">int</span> tmp = f4(tmpabcde[<span class="number">0</span>], <span class="number">5</span>) +</span><br><span class="line">                    f2(tmpabcde[<span class="number">1</span>], tmpabcde[<span class="number">2</span>], tmpabcde[<span class="number">3</span>]) + tmpabcde[<span class="number">4</span>] +</span><br><span class="line">                    tmpData[m] + <span class="number">0xca62c1d6</span>;</span><br><span class="line">            tmpabcde[<span class="number">4</span>] = tmpabcde[<span class="number">3</span>];</span><br><span class="line">            tmpabcde[<span class="number">3</span>] = tmpabcde[<span class="number">2</span>];</span><br><span class="line">            tmpabcde[<span class="number">2</span>] = f4(tmpabcde[<span class="number">1</span>], <span class="number">30</span>);</span><br><span class="line">            tmpabcde[<span class="number">1</span>] = tmpabcde[<span class="number">0</span>];</span><br><span class="line">            tmpabcde[<span class="number">0</span>] = tmp;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i2 = <span class="number">0</span>; i2 &lt; tmpabcde.length; i2++) &#123;</span><br><span class="line">            digestInt[i2] = digestInt[i2] + tmpabcde[i2];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> n = <span class="number">0</span>; n &lt; tmpData.length; n++) &#123;</span><br><span class="line">            tmpData[n] = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 4字节数组转换为整数</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">byteArrayToInt</span><span class="params">(<span class="keyword">byte</span>[] bytedata, <span class="keyword">int</span> i)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> ((bytedata[i] &amp; <span class="number">0xff</span>) &lt;&lt; <span class="number">24</span>) | ((bytedata[i + <span class="number">1</span>] &amp; <span class="number">0xff</span>) &lt;&lt; <span class="number">16</span>) |</span><br><span class="line">                ((bytedata[i + <span class="number">2</span>] &amp; <span class="number">0xff</span>) &lt;&lt; <span class="number">8</span>) | (bytedata[i + <span class="number">3</span>] &amp; <span class="number">0xff</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 整数转换为4字节数组</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">intToByteArray</span><span class="params">(<span class="keyword">int</span> intValue, <span class="keyword">byte</span>[] byteData, <span class="keyword">int</span> i)</span> </span>&#123;</span><br><span class="line">        byteData[i] = (<span class="keyword">byte</span>) (intValue &gt;&gt;&gt; <span class="number">24</span>);</span><br><span class="line">        byteData[i + <span class="number">1</span>] = (<span class="keyword">byte</span>) (intValue &gt;&gt;&gt; <span class="number">16</span>);</span><br><span class="line">        byteData[i + <span class="number">2</span>] = (<span class="keyword">byte</span>) (intValue &gt;&gt;&gt; <span class="number">8</span>);</span><br><span class="line">        byteData[i + <span class="number">3</span>] = (<span class="keyword">byte</span>) intValue;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 将字节转换为十六进制字符串</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">byteToHexString</span><span class="params">(<span class="keyword">byte</span> ib)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">char</span>[] Digit = &#123;</span><br><span class="line">                <span class="string">'0'</span>, <span class="string">'1'</span>, <span class="string">'2'</span>, <span class="string">'3'</span>, <span class="string">'4'</span>, <span class="string">'5'</span>, <span class="string">'6'</span>, <span class="string">'7'</span>, <span class="string">'8'</span>, <span class="string">'9'</span>, <span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>,</span><br><span class="line">                <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span></span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="keyword">char</span>[] ob = <span class="keyword">new</span> <span class="keyword">char</span>[<span class="number">2</span>];</span><br><span class="line">        ob[<span class="number">0</span>] = Digit[(ib &gt;&gt;&gt; <span class="number">4</span>) &amp; <span class="number">0X0F</span>];</span><br><span class="line">        ob[<span class="number">1</span>] = Digit[ib &amp; <span class="number">0X0F</span>];</span><br><span class="line">        String s = <span class="keyword">new</span> String(ob);</span><br><span class="line">        <span class="keyword">return</span> s;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 将字节数组转换为十六进制字符串</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">byteArrayToHexString</span><span class="params">(<span class="keyword">byte</span>[] bytearray)</span> </span>&#123;</span><br><span class="line">        String strDigest = <span class="string">""</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; bytearray.length; i++) &#123;</span><br><span class="line">            strDigest += byteToHexString(bytearray[i]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> strDigest;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 计算sha-1摘要，返回相应的字节数组</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">byte</span>[] getDigestOfBytes(<span class="keyword">byte</span>[] byteData) &#123;</span><br><span class="line">        process_input_bytes(byteData);</span><br><span class="line">        <span class="keyword">byte</span>[] digest = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">20</span>];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; digestInt.length; i++) &#123;</span><br><span class="line">            intToByteArray(digestInt[i], digest, i * <span class="number">4</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> digest;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 计算sha-1摘要，返回相应的十六进制字符串</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getDigestOfString</span><span class="params">(<span class="keyword">byte</span>[] byteData)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> byteArrayToHexString(getDigestOfBytes(byteData));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/31/SHA1加密/" data-id="ckcc5iwj4000oq4uwdlx05j0c" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/util/">util</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-ZipUtil" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/31/ZipUtil/" class="article-date">
  <time datetime="2018-05-31T08:09:11.000Z" itemprop="datePublished">2018-05-31</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/31/ZipUtil/">ZipUtil</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="ZipUtil"><a href="#ZipUtil" class="headerlink" title="ZipUtil"></a>ZipUtil</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ZipUtil</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">     <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> BUFFER = <span class="number">2048</span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">unzip</span><span class="params">(String filepath,String unzipFolder)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            String fileName = <span class="string">"E:\\test\\myfiles.zip"</span>;</span><br><span class="line">            String filePath = <span class="string">"E:\\test\\"</span>;</span><br><span class="line">            fileName=filepath;</span><br><span class="line">            filePath=unzipFolder;</span><br><span class="line"></span><br><span class="line">            ZipFile zipFile = <span class="keyword">new</span> ZipFile(fileName);</span><br><span class="line">            Enumeration emu = zipFile.entries();</span><br><span class="line">            <span class="keyword">int</span> i=<span class="number">0</span>;</span><br><span class="line">            <span class="keyword">while</span>(emu.hasMoreElements())&#123;</span><br><span class="line">                ZipEntry entry = (ZipEntry)emu.nextElement();</span><br><span class="line">                <span class="comment">//会把目录作为一个file读出一次，所以只建立目录就可以，之下的文件还会被迭代到。</span></span><br><span class="line">                <span class="keyword">if</span> (entry.isDirectory())</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">new</span> File(filePath + entry.getName()).mkdirs();</span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                BufferedInputStream bis = <span class="keyword">new</span> BufferedInputStream(zipFile.getInputStream(entry));</span><br><span class="line">                File file = <span class="keyword">new</span> File(filePath + entry.getName());</span><br><span class="line">                <span class="comment">//加入这个的原因是zipfile读取文件是随机读取的，这就造成可能先读取一个文件</span></span><br><span class="line">                <span class="comment">//而这个文件所在的目录还没有出现过，所以要建出目录来。</span></span><br><span class="line">                File parent = file.getParentFile();</span><br><span class="line">                <span class="keyword">if</span>(parent != <span class="keyword">null</span> &amp;&amp; (!parent.exists()))&#123;</span><br><span class="line">                    parent.mkdirs();</span><br><span class="line">                &#125;</span><br><span class="line">                FileOutputStream fos = <span class="keyword">new</span> FileOutputStream(file);</span><br><span class="line">                BufferedOutputStream bos = <span class="keyword">new</span> BufferedOutputStream(fos,BUFFER);</span><br><span class="line"></span><br><span class="line">                <span class="keyword">int</span> count;</span><br><span class="line">                <span class="keyword">byte</span> data[] = <span class="keyword">new</span> <span class="keyword">byte</span>[BUFFER];</span><br><span class="line">                <span class="keyword">while</span> ((count = bis.read(data, <span class="number">0</span>, BUFFER)) != -<span class="number">1</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    bos.write(data, <span class="number">0</span>, count);</span><br><span class="line">                &#125;</span><br><span class="line">                bos.flush();</span><br><span class="line">                bos.close();</span><br><span class="line">                bis.close();</span><br><span class="line">            &#125;</span><br><span class="line">            zipFile.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/31/ZipUtil/" data-id="ckcc5iwjr001aq4uw1ksq8ri1" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/util/">util</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-linux/linux简单命令" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/31/linux/linux简单命令/" class="article-date">
  <time datetime="2018-05-31T07:09:11.000Z" itemprop="datePublished">2018-05-31</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/31/linux/linux简单命令/">linux简单命令</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="linux简单命令"><a href="#linux简单命令" class="headerlink" title="linux简单命令"></a>linux简单命令</h5><ol>
<li><p>ls [选项] [目录名 | 列出相关目录下的所有目录和文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">-a  列出包括.a开头的隐藏文件的所有文件</span><br><span class="line">-A  通-a，但不列出"."和".."</span><br><span class="line">-l  列出文件的详细信息</span><br><span class="line">-c  根据ctime排序显示</span><br><span class="line">-t  根据文件修改时间排序</span><br><span class="line">---color[=WHEN] 用色彩辨别文件类型 WHEN 可以是'never'、'always'或'auto'其中之一</span><br><span class="line">   白色：表示普通文件</span><br><span class="line">   蓝色：表示目录</span><br><span class="line">   绿色：表示可执行文件</span><br><span class="line">   红色：表示压缩文件</span><br><span class="line">   浅蓝色：链接文件</span><br><span class="line">   红色闪烁：表示链接的文件有问题</span><br><span class="line">   黄色：表示设备文件</span><br><span class="line">   灰色：表示其它文件</span><br></pre></td></tr></table></figure>
</li>
<li><p>mv [选项] 源文件或目录 目录或多个源文件 | 移动或重命名文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">-b  覆盖前做备份</span><br><span class="line">-f  如存在不询问而强制覆盖</span><br><span class="line">-i  如存在则询问是否覆盖</span><br><span class="line">-u  较新才覆盖</span><br><span class="line">-t  将多个源文件移动到统一目录下，目录参数在前，文件参数在后</span><br><span class="line">eg:</span><br><span class="line">   mv a /tmp/ 将文件a移动到 /tmp目录下</span><br><span class="line">   mv a b 将a命名为b</span><br><span class="line">   mv /home/zenghao test1.txt test2.txt test3.txt</span><br></pre></td></tr></table></figure>
</li>
<li><p>cp [选项] 源文件或目录 目录或多个源文件 | 将源文件复制至目标文件，或将多个源文件复制至目标目录。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">-r -R 递归复制该目录及其子目录内容</span><br><span class="line">-p  连同档案属性一起复制过去</span><br><span class="line">-f  不询问而强制复制</span><br><span class="line">-s  生成快捷方式</span><br><span class="line">-a  将档案的所有特性都一起复制</span><br></pre></td></tr></table></figure>
</li>
<li><p>scp [参数] [原路径] [目标路径] | 在Linux服务器之间复制文件和目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">-v  详细显示输出的具体情况</span><br><span class="line">-r  递归复制整个目录</span><br><span class="line">(1) 复制文件：  </span><br><span class="line">命令格式：  </span><br><span class="line">scp local_file remote_username@remote_ip:remote_folder  </span><br><span class="line">或者  </span><br><span class="line">scp local_file remote_username@remote_ip:remote_file  </span><br><span class="line">或者  </span><br><span class="line">scp local_file remote_ip:remote_folder  </span><br><span class="line">或者  </span><br><span class="line">scp local_file remote_ip:remote_file  </span><br><span class="line">第1,2个指定了用户名，命令执行后需要输入用户密码，第1个仅指定了远程的目录，文件名字不变，第2个指定了文件名  </span><br><span class="line">第3,4个没有指定用户名，命令执行后需要输入用户名和密码，第3个仅指定了远程的目录，文件名字不变，第4个指定了文件名   </span><br><span class="line">(2) 复制目录：  </span><br><span class="line">命令格式：  </span><br><span class="line">scp -r local_folder remote_username@remote_ip:remote_folder  </span><br><span class="line">或者  </span><br><span class="line">scp -r local_folder remote_ip:remote_folder  </span><br><span class="line">第1个指定了用户名，命令执行后需要输入用户密码；  </span><br><span class="line">第2个没有指定用户名，命令执行后需要输入用户名和密码；</span><br><span class="line">eg:</span><br><span class="line">   从 本地 复制到 远程</span><br><span class="line">   scp /home/daisy/full.tar.gz root@172.19.2.75:/home/root </span><br><span class="line">   从 远程 复制到 本地</span><br><span class="line">   scp root@/172.19.2.75:/home/root/full.tar.gz /home/daisy/full.tar.gz</span><br></pre></td></tr></table></figure>
</li>
<li><p>rm [选项] 文件 | 删除文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-r  删除文件夹</span><br><span class="line">-f  删除不提示</span><br><span class="line">-i  删除提示</span><br><span class="line">-v  详细显示进行步骤</span><br></pre></td></tr></table></figure>
</li>
<li><p>touch [选项] 文件 | 创建空文件或更新文件时间</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-a  只修改存取时间</span><br><span class="line">-m  值修改变动时间</span><br><span class="line">-r  eg:touch -r a b ,使b的时间和a相同</span><br><span class="line">-t  指定特定的时间 eg:touch -t 201211142234.50 log.log </span><br><span class="line">   -t time [[CC]YY]MMDDhhmm[.SS],C:年前两位</span><br></pre></td></tr></table></figure>
</li>
<li><p>pwd 查看当前所在路径</p>
</li>
<li><p>cd 改变当前目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">- ：返回上层目录</span><br><span class="line">.. :返回上层目录</span><br><span class="line">回车  ：返回主目录</span><br><span class="line">/   :根目录</span><br></pre></td></tr></table></figure>
</li>
<li><p>mkdir [选项] 目录… | 创建新目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">-p  递归创建目录，若父目录不存在则依次创建</span><br><span class="line">-m  自定义创建目录的权限  eg:mkdir -m 777 hehe</span><br><span class="line">-v  显示创建目录的详细信息</span><br></pre></td></tr></table></figure>
</li>
<li><p>rmdir 删除空目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-v  显示执行过程</span><br><span class="line">-p  若自父母删除后父目录为空则一并删除</span><br></pre></td></tr></table></figure>
</li>
<li><p>rm [选项] 文件… | 一个或多个文件或目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-f  忽略不存在的文件，不给出提示</span><br><span class="line">-i  交互式删除</span><br><span class="line">-r  将列出的目录及其子目录递归删除</span><br><span class="line">-v  列出详细信息</span><br></pre></td></tr></table></figure>
</li>
<li><p>echo：显示内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-n  输出后不换行</span><br><span class="line">-e  遇到转义字符特殊处理  </span><br><span class="line">   eg:</span><br><span class="line">       echo "he\nhe"   显示he\nhe</span><br><span class="line">       ehco -e "he\nhe"    显示he(换行了)he</span><br></pre></td></tr></table></figure>
</li>
<li><p>cat [选项] [文件]..| 一次显示整个文件或从键盘创建一个文件或将几个文件合并成一个文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">-n  编号文件内容再输出</span><br><span class="line">-E  在结束行提示$</span><br></pre></td></tr></table></figure>
</li>
<li><p>tac | 反向显示</p>
</li>
<li><p>more | 按页查看文章内容，从前向后读取文件，因此在启动时就加载整个文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">+n  从第n行开始显示</span><br><span class="line">-n  每次查看n行数据</span><br><span class="line">+/String    搜寻String字符串位置，从其前两行开始查看</span><br><span class="line">-c  清屏再显示</span><br><span class="line">-p  换页时清屏</span><br></pre></td></tr></table></figure>
</li>
<li><p>less | 可前后移动地逐屏查看文章内容，在查看前不会加载整个文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">-m  显示类似于more命令的百分比</span><br><span class="line">-N  显示行号</span><br><span class="line">/   字符串：向下搜索“字符串”的功能</span><br><span class="line">?   字符串：向上搜索“字符串”的功能</span><br><span class="line">n   重复前一个搜索（与 / 或 ? 有关）</span><br><span class="line">N   反向重复前一个搜索（与 / 或 ? 有关）</span><br><span class="line">b   向后翻一页</span><br><span class="line">d   向后翻半页</span><br></pre></td></tr></table></figure>
</li>
<li><p>nl [选项]… [文件]… | 将输出内容自动加上行号 </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-b </span><br><span class="line">-b a 不论是否有空行，都列出行号（类似 cat -n) </span><br><span class="line">-b t 空行则不列行号（默认） </span><br><span class="line">-n 有ln rn rz三个参数，分别为再最左方显示，最右方显示不加0，最右方显示加0</span><br></pre></td></tr></table></figure>
</li>
<li><p>head [参数]… [文件]… | 显示档案开头，默认开头10行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-v  显示文件名</span><br><span class="line">-c number   显示前number个字符,若number为负数,则显示除最后number个字符的所有内容</span><br><span class="line">-number/n (+)number     显示前number行内容，</span><br><span class="line">-n number   若number为负数，则显示除最后number行数据的所有内容</span><br></pre></td></tr></table></figure>
</li>
<li><p>tail [必要参数] [选择参数] [文件] | 显示文件结尾内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-v  显示详细的处理信息</span><br><span class="line">-q  不显示处理信息</span><br><span class="line">-num/-n (-)num      显示最后num行内容</span><br><span class="line">-n +num 从第num行开始显示后面的数据</span><br><span class="line">-c  显示最后c个字符</span><br><span class="line">-f  循环读取</span><br></pre></td></tr></table></figure>
</li>
<li><p>vi 编辑文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">:w filename 将文章以指定的文件名保存起来  </span><br><span class="line">:wq 保存并退出</span><br><span class="line">:q! 不保存而强制退出</span><br><span class="line">命令行模式功能键</span><br><span class="line">1）插入模式</span><br><span class="line">   按「i」切换进入插入模式「insert mode」，按"i"进入插入模式后是从光标当前位置开始输入文件；</span><br><span class="line">   按「a」进入插入模式后，是从目前光标所在位置的下一个位置开始输入文字；</span><br><span class="line">   按「o」进入插入模式后，是插入新的一行，从行首开始输入文字。</span><br><span class="line"></span><br><span class="line">2）从插入模式切换为命令行模式</span><br><span class="line"> 按「ESC」键。</span><br><span class="line">3）移动光标</span><br><span class="line">　　vi可以直接用键盘上的光标来上下左右移动，但正规的vi是用小写英文字母「h」、「j」、「k」、「l」，分别控制光标左、下、上、右移一格。</span><br><span class="line">　　按「ctrl」+「b」：屏幕往"后"移动一页。</span><br><span class="line">　　按「ctrl」+「f」：屏幕往"前"移动一页。</span><br><span class="line">　　按「ctrl」+「u」：屏幕往"后"移动半页。</span><br><span class="line">　　按「ctrl」+「d」：屏幕往"前"移动半页。</span><br><span class="line">　　按数字「0」：移到文章的开头。</span><br><span class="line">　　按「G」：移动到文章的最后。</span><br><span class="line">　　按「$」：移动到光标所在行的"行尾"。</span><br><span class="line">　　按「^」：移动到光标所在行的"行首"</span><br><span class="line">　　按「w」：光标跳到下个字的开头</span><br><span class="line">　　按「e」：光标跳到下个字的字尾</span><br><span class="line">　　按「b」：光标回到上个字的开头</span><br><span class="line">　　按「#l」：光标移到该行的第#个位置，如：5l,56l。</span><br><span class="line"></span><br><span class="line">4）删除文字</span><br><span class="line">　　「x」：每按一次，删除光标所在位置的"后面"一个字符。</span><br><span class="line">　　「#x」：例如，「6x」表示删除光标所在位置的"后面"6个字符。</span><br><span class="line">　　「X」：大写的X，每按一次，删除光标所在位置的"前面"一个字符。</span><br><span class="line">　　「#X」：例如，「20X」表示删除光标所在位置的"前面"20个字符。</span><br><span class="line">　　「dd」：删除光标所在行。</span><br><span class="line">　　「#dd」：从光标所在行开始删除#行</span><br><span class="line"></span><br><span class="line">5）复制</span><br><span class="line">　　「yw」：将光标所在之处到字尾的字符复制到缓冲区中。</span><br><span class="line">　　「#yw」：复制#个字到缓冲区</span><br><span class="line">　　「yy」：复制光标所在行到缓冲区。</span><br><span class="line">　　「#yy」：例如，「6yy」表示拷贝从光标所在的该行"往下数"6行文字。</span><br><span class="line">　　「p」：将缓冲区内的字符贴到光标所在位置。注意：所有与"y"有关的复制命令都必须与"p"配合才能完成复制与粘贴功能。</span><br><span class="line"></span><br><span class="line">6）替换</span><br><span class="line">　　「r」：替换光标所在处的字符。</span><br><span class="line">　　「R」：替换光标所到之处的字符，直到按下「ESC」键为止。</span><br><span class="line"></span><br><span class="line">7）回复上一次操作</span><br><span class="line">　　「u」：如果您误执行一个命令，可以马上按下「u」，回到上一个操作。按多次"u"可以执行多次回复。</span><br><span class="line"></span><br><span class="line">8）更改</span><br><span class="line">　　「cw」：更改光标所在处的字到字尾处</span><br><span class="line">　　「c#w」：例如，「c3w」表示更改3个字</span><br><span class="line"></span><br><span class="line">9）跳至指定的行</span><br><span class="line">　　「ctrl」+「g」列出光标所在行的行号。</span><br><span class="line">　　「#G」：例如，「15G」，表示移动光标至文章的第15行行首。</span><br></pre></td></tr></table></figure>
</li>
<li><p>which 可执行文件名称 | 查看可执行文件的位置，在PATH变量指定的路径中查看系统命令是否存在及其位置</p>
</li>
<li><p>whereis [-bmsu] [BMS 目录名 -f ] 文件名| 定位可执行文件、源代码文件、帮助文件在文件系统中的位置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">-b   定位可执行文件。</span><br><span class="line">-m   定位帮助文件。</span><br><span class="line">-s   定位源代码文件。</span><br><span class="line">-u   搜索默认路径下除可执行文件、源代码文件、帮助文件以外的其它文件。</span><br><span class="line">-B   指定搜索可执行文件的路径。</span><br><span class="line">-M   指定搜索帮助文件的路径。</span><br><span class="line">-S   指定搜索源代码文件的路径。</span><br></pre></td></tr></table></figure>
</li>
<li><p>locate | 通过搜寻数据库快速搜寻档案</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-r  使用正规运算式做寻找的条件</span><br></pre></td></tr></table></figure>
</li>
<li><p>find find [PATH] [option] [action] | 在文件树种查找文件，并作出相应的处理</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">选项与参数：</span><br><span class="line">1. 与时间有关的选项：共有 -atime, -ctime 与 -mtime 和-amin,-cmin与-mmin，以 -mtime 说明</span><br><span class="line">   -mtime n ：n 为数字，意义为在 n 天之前的『一天之内』被更动过内容的档案；</span><br><span class="line">   -mtime +n ：列出在 n 天之前(不含 n 天本身)被更动过内容的档案档名；</span><br><span class="line">   -mtime -n ：列出在 n 天之内(含 n 天本身)被更动过内容的档案档名。</span><br><span class="line">   -newer file ：file 为一个存在的档案，列出比 file 还要新的档案档名</span><br><span class="line"></span><br><span class="line">2. 与使用者或组名有关的参数：</span><br><span class="line">   -uid n ：n 为数字，这个数字是用户的账号 ID，亦即 UID</span><br><span class="line">   -gid n ：n 为数字，这个数字是组名的 ID，亦即 GID</span><br><span class="line">   -user name ：name 为使用者账号名称！例如 dmtsai</span><br><span class="line">   -group name：name 为组名，例如 users ；</span><br><span class="line">   -nouser ：寻找档案的拥有者不存在 /etc/passwd 的人！</span><br><span class="line">   -nogroup ：寻找档案的拥有群组不存在于 /etc/group 的档案！</span><br><span class="line"></span><br><span class="line">3. 与档案权限及名称有关的参数：</span><br><span class="line">   -name filename：搜寻文件名为 filename 的档案（可使用通配符）</span><br><span class="line">   -size [+-]SIZE：搜寻比 SIZE 还要大(+)或小(-)的档案。这个 SIZE 的规格有：</span><br><span class="line">       c: 代表 byte</span><br><span class="line">       k: 代表 1024bytes。所以，要找比 50KB还要大的档案，就是『 -size +50k 』</span><br><span class="line">   -type TYPE ：搜寻档案的类型为 TYPE 的，类型主要有：</span><br><span class="line">       一般正规档案 (f)</span><br><span class="line">       装置档案 (b, c)</span><br><span class="line">       目录 (d)</span><br><span class="line">       连结档 (l)</span><br><span class="line">       socket (s)</span><br><span class="line">       FIFO (p)</span><br><span class="line">   -perm mode ：搜寻档案权限『刚好等于』 mode的档案，这个mode为类似chmod的属性值，举例来说，-rwsr-xr-x 的属性为4755！</span><br><span class="line">   -perm -mode ：搜寻档案权限『必须要全部囊括 mode 的权限』的档案，举例来说，</span><br><span class="line">       我们要搜寻-rwxr--r-- 亦即 0744 的档案，使用-perm -0744，当一个档案的权限为 -rwsr-xr-x ，亦即 4755 时，也会被列出来，因为 -rwsr-xr-x 的属性已经囊括了 -rwxr--r-- 的属性了。</span><br><span class="line">   -perm +mode ：搜寻档案权限『包含任一 mode 的权限』的档案，举例来</span><br><span class="line">       说，我们搜寻-rwxr-xr-x ，亦即 -perm +755 时，但一个文件属性为 -rw-------也会被列出来，因为他有 -rw.... 的属性存在！</span><br><span class="line">4. 额外可进行的动作：</span><br><span class="line">   -exec command ：command 为其他指令，-exec 后面可再接额外的指令来处理搜寻到的结果。</span><br><span class="line">   -print ：将结果打印到屏幕上，这个动作是预设动作！</span><br><span class="line">   eg:</span><br><span class="line">       find / -perm +7000 -exec ls -l &#123;&#125; \; ,额外指令以-exec开头，以\;结尾&#123;&#125;代替前面找到的内容</span><br><span class="line">   | xargs </span><br><span class="line">       -i  默认的前面输出用&#123;&#125;代替 </span><br><span class="line">       eg:</span><br><span class="line">           find . -name "*.log" | xargs -i mv &#123;&#125; test4</span><br></pre></td></tr></table></figure>
</li>
<li><p>grep ‘正则表达式’ 文件名 | 用正则表达式搜索文本，并把匹配的行打印出来</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-c  只输出匹配行的计数。</span><br><span class="line">-I  不区分大小写(只适用于单字符)。</span><br><span class="line">-l  只显示文件名</span><br><span class="line">-v  显示不包含匹配文本的所有行。</span><br><span class="line">-n  显示匹配行数据及其行号</span><br></pre></td></tr></table></figure>
</li>
<li><p>gzip [-cdtv#] 檔名 | 压缩、解压缩，源文件都不再存在</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-d  进行解压缩</span><br><span class="line">-c  将压缩的数据输出到屏幕上</span><br><span class="line">-v  :显示原档案/压缩文件案的压缩比等信息</span><br><span class="line"><span class="meta">-#</span><span class="bash">  ：压缩等级，-1最快，但压缩比最差，=9最慢，但压缩比最好</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>gunzip | 解压缩</p>
</li>
<li><p>bzip2 | 压缩、解压缩</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-d  :解压</span><br><span class="line">-z  :压缩</span><br><span class="line">-k  :保留源文件</span><br><span class="line">-c ：将压缩的过程产生的数据输出到屏幕上！</span><br><span class="line">-v ：可以显示出原档案/压缩文件案的压缩比等信息；</span><br><span class="line"><span class="meta">-#</span><span class="bash"> ：与 gzip 同样的，都是在计算压缩比的参数， -9 最佳， -1 最快！</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>bzcat 读取数据而无需解压</p>
</li>
<li>tar [主选项+辅选项] 文件或者目录 | 多个目录或档案打包、压缩成一个大档案</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">主选项：</span><br><span class="line">   -c  建立打包档案，可搭配 -v 来察看过程中被打包的档名(filename)</span><br><span class="line">   -t  察看打包档案的内容含有哪些档名，重点在察看『档名』就是了；</span><br><span class="line">   -x  解打包或解压缩的功能，可以搭配 -C (大写) 在特定目录解开</span><br><span class="line">辅选项：</span><br><span class="line">   -j  透过 bzip2 的支持进行压缩/解压缩：此时档名最好为 *.tar.bz2</span><br><span class="line">   -z  透过 gzip 的支持进行压缩/解压缩：此时档名最好为 *.tar.gz</span><br><span class="line">   -v  在压缩/解压缩的过程中，将正在处理的文件名显示出来！</span><br><span class="line">   -f filename -f 后面要立刻接要被处理的档名！</span><br><span class="line">   -C 目录   这个选项用在解压缩，若要在特定目录解压缩，可以使用这个选项。</span><br><span class="line">   --exclude FILE：在压缩打包过程中忽略某文件 eg: tar --exclude /home/zenghao -zcvf myfile.tar.gz /home/* /etc</span><br><span class="line">   -p  保留备份数据的原本权限与属性，常用于备份(-c)重要的配置文件</span><br><span class="line">   -P(大写）  保留绝对路径，亦即允许备份数据中含有根目录存在之意；</span><br><span class="line">eg:</span><br><span class="line">   压 缩：tar -jcvf filename.tar.bz2 要被压缩的档案或目录名称</span><br><span class="line">   查 询：tar -jtvf filename.tar.bz2</span><br><span class="line">   解压缩：tar -jxvf filename.tar.bz2 -C 欲解压缩的目录</span><br></pre></td></tr></table></figure>
<ol>
<li>exit 退出当前shell </li>
<li>logout 退出登录shell </li>
<li>shutdown -h now</li>
<li>users 显示当前登录系统地用户</li>
<li><p>who 登录在本机的用户与来源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-H或--heading 　显示各栏位的标题信息列。</span><br></pre></td></tr></table></figure>
</li>
<li><p>w 登录在本机的用户及其运行的程序</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-s 　使用简洁格式列表，不显示用户登入时间，终端机阶段作业和程序所耗费的CPU时间。</span><br><span class="line">-h 　不显示各栏位的标题信息列。</span><br></pre></td></tr></table></figure>
</li>
<li><p>write 给当前联机的用户发消息</p>
</li>
<li>wall 给所有登录再本机的用户发消息</li>
<li>last 查看用户的登陆日志</li>
<li>lastlog 查看每个用户最后的登陆时间</li>
<li><p>finger [选项] [使用者] [用户@主机] | 查看用户信息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">-s 显示用户的注册名、实际姓名、终端名称、写状态、停滞时间、登录时间等信息</span><br><span class="line">-l 除了用-s选项显示的信息外，还显示用户主目录、登录shell、邮件状态等信息，以及用户主目录下的.plan、.project和.forward文件的内容。</span><br><span class="line">-p 除了不显示.plan文件和.project文件以外，与-l选项相同</span><br></pre></td></tr></table></figure>
</li>
<li><p>hostname 查看主机名</p>
</li>
<li>alias ii = “ls -l” | 添加别名</li>
<li>unalias ii | 清除别名</li>
<li><p>useradd [-u UID] [-g 初始群组] [-G 次要群组] [-c 说明栏] [-d 家目录绝对路径] [-s shell] 使用者账号名 | 新增用户</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-M  不建立用户家目录！(系统账号默认值)</span><br><span class="line">-m  建立用户家目录！(一般账号默认值)</span><br><span class="line">-r  建立一个系统的账号，这个账号的 UID 会有限制 </span><br><span class="line">-e  账号失效日期，格式为『YYYY-MM-DD』</span><br><span class="line">-D  查看useradd的各项默认值</span><br></pre></td></tr></table></figure>
</li>
<li><p>passwd | 修改密码</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">-l  使密码失效</span><br><span class="line">-u  与-l相对，用户解锁</span><br><span class="line">-S  列出登陆用户passwd文件内的相关参数</span><br><span class="line">-n  后面接天数，shadow 的第 4 字段，多久不可修改密码天数</span><br><span class="line">-x  后面接天数，shadow 的第 5 字段，多久内必须要更动密码</span><br><span class="line">-w  后面接天数，shadow 的第 6 字段，密码过期前的警告天数</span><br><span class="line">-i  后面接『日期』，shadow 的第 7 字段，密码失效日期</span><br><span class="line">使用管道刘设置密码：echo "zeng" | passwd --stdin zenghao</span><br></pre></td></tr></table></figure>
</li>
<li><p>userdel 删除用户</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-r  用户文件一并删除</span><br></pre></td></tr></table></figure>
</li>
<li><p>chage [-ldEImMW] 账号名 | 修改用户密码的相关属性</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">-l  列出该账号的详细密码参数；</span><br><span class="line">-d  后面接日期，修改 shadow 第三字段(最近一次更改密码的日期)，格式YYYY-MM-DD</span><br><span class="line">-E  后面接日期，修改 shadow 第八字段(账号失效日)，格式 YYYY-MM-DD</span><br><span class="line">-I  后面接天数，修改 shadow 第七字段(密码失效日期)</span><br><span class="line">-m  后面接天数，修改 shadow 第四字段(密码最短保留天数)</span><br><span class="line">-M  后面接天数，修改 shadow 第五字段(密码多久需要进行变更)</span><br><span class="line">-W  后面接天数，修改 shadow 第六字段(密码过期前警告日期)</span><br></pre></td></tr></table></figure>
</li>
<li><p>usermod [-cdegGlsuLU] username | 修改用户的相关属性</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">-c  后面接账号的说明，即 /etc/passwd 第五栏的说明栏，可以加入一些账号的说明。</span><br><span class="line">-d  后面接账号的家目录，即修改 /etc/passwd 的第六栏；</span><br><span class="line">-e  后面接日期，格式是 YYYY-MM-DD 也就是在 /etc/shadow 内的第八个字段数据啦！</span><br><span class="line">-f  后面接天数为 shadow 的第七字段。</span><br><span class="line">-g  后面接初始群组，修改 /etc/passwd 的第四个字段，亦即是GID的字段！</span><br><span class="line">-G  后面接次要群组，修改这个使用者能够支持的群组</span><br><span class="line">-l  后面接账号名称。亦即是修改账号名称， /etc/passwd 的第一栏！</span><br><span class="line">-s  后面接 Shell 的实际档案，例如 /bin/bash 或 /bin/csh 等等。</span><br><span class="line">-u  后面接 UID 数字啦！即 /etc/passwd 第三栏的资料；</span><br><span class="line">-L  冻结密码</span><br><span class="line">-U  解冻密码</span><br></pre></td></tr></table></figure>
</li>
<li><p>id [username] | 查看用户相关的id信息，还可以用来判断用户是否存在</p>
</li>
<li>groups 查看登陆用户支持的群组， 第一个输出的群组为有效群组</li>
<li>newgrp 切换有效群组</li>
<li><p>groupadd [-g gid] 组名 | 添加组</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-g  设定添加组的特定组id</span><br></pre></td></tr></table></figure>
</li>
<li><p>groupmod [-g gid] [-n group_name] 群组名 | 修改组信息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-g  修改既有的 GID 数字</span><br><span class="line">-n  修改既有的组名</span><br></pre></td></tr></table></figure>
</li>
<li><p>groupdel [groupname] | 删除群组</p>
</li>
<li><p>gpasswd | 群组管理员功能</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">root管理员动作：</span><br><span class="line">   -gpasswd groupname 设定密码</span><br><span class="line">   -gpasswd [-A user1,...] [-M user3,...] groupname</span><br><span class="line">       -A  将 groupname 的主控权交由后面的使用者管理(该群组的管理员)</span><br><span class="line">       -M  将某些账号加入这个群组当中</span><br><span class="line">   -gpasswd [-r] groupname</span><br><span class="line">       -r  将 groupname 的密码移除</span><br><span class="line">群组管理员动作：</span><br><span class="line">   - gpasswd [-ad] user groupname </span><br><span class="line">       -a  将某位使用者加入到 groupname 这个群组当中</span><br><span class="line">       -d  将某位使用者移除出 groupname 这个群组当中</span><br></pre></td></tr></table></figure>
</li>
<li><p>chfn修改个人信息</p>
</li>
<li><p>mount [-t vfstype] [-o options] device dir</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">    -ro 采用只读方式挂接设备</span><br><span class="line">    -rw 采用读写方式挂接设备</span><br><span class="line">    eg:mount /home/mydisk.iso /tmp/mnt 通过mnt访问mydisk内的内容</span><br><span class="line">``` </span><br><span class="line">59. umount 取消挂载</span><br><span class="line">60. cut</span><br><span class="line">```shell</span><br><span class="line">    -b ：以字节为单位进行分割。这些字节位置将忽略多字节字符边界，除非也指定了 -n 标志。</span><br><span class="line">    -c ：以字符为单位进行分割。</span><br><span class="line">    -d ：自定义分隔符，默认为制表符。</span><br><span class="line">    -f  ：与-d一起使用，指定显示哪个区域。</span><br></pre></td></tr></table></figure>
</li>
<li><p>sort</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-n   依照数值的大小排序。</span><br><span class="line">-o&lt;输出文件&gt;   将排序后的结果存入指定的文件。</span><br><span class="line">-r   以相反的顺序来排序。</span><br><span class="line">-t&lt;分隔字符&gt;   指定排序时所用的栏位分隔字符。</span><br><span class="line">-k  选择以哪个区间进行排序。</span><br></pre></td></tr></table></figure>
</li>
<li><p>wc 统计指定文件中的字节数、字数、行数, 并将统计结果显示输出</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-l filename 报告行数</span><br><span class="line">-c filename 报告字节数</span><br><span class="line">-m filename 报告字符数</span><br><span class="line">-w filename 报告单词数</span><br></pre></td></tr></table></figure>
</li>
<li><p>uniq 去除文件中相邻的重复行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-c或——count：在每列旁边显示该行重复出现的次数；</span><br><span class="line">-d或--repeated：仅显示重复出现的行列；</span><br><span class="line">-f&lt;栏位&gt;或--skip-fields=&lt;栏位&gt;：忽略比较指定的栏位；</span><br><span class="line">-s&lt;字符位置&gt;或--skip-chars=&lt;字符位置&gt;：忽略比较指定的字符；</span><br><span class="line">-u或——unique：仅显示出一次的行列；</span><br><span class="line">-w&lt;字符位置&gt;或--check-chars=&lt;字符位置&gt;：指定要比较的字符。</span><br></pre></td></tr></table></figure>
</li>
<li><p>set 显示环境变量和普通变量 </p>
</li>
<li>env 显示环境变量 </li>
<li>export 把普通变量变成环境变量 </li>
<li><p>unset 删除一个环境变量</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">aaa()&#123;&#125; 定义函数</span><br></pre></td></tr></table></figure>
</li>
<li><p>read</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-p  接提示字符</span><br><span class="line">-t  接等待的秒数</span><br></pre></td></tr></table></figure>
</li>
<li><p>declare、typeset</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">-i 声明为整数</span><br><span class="line">-a 声明为数组</span><br><span class="line">-f 声明为函数</span><br><span class="line">-r 声明为只读</span><br></pre></td></tr></table></figure>
</li>
<li><p>ulimit 限制使用者的某些系统资源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-f  此 shell 可以建立的最大档案容量 (一般可能设定为 2GB)单位为 Kbytes eg: ulimit -f 1024 限制使用者仅能建立 1MBytes 以下的容量的档案</span><br></pre></td></tr></table></figure>
</li>
<li><p>df [选项] [文件] | 显示指定磁盘文件的可用空间,如果没有文件名被指定，则所有当前被挂载的文件系统的可用空间将被显示</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">   </span><br><span class="line">-a  显示全部文件系统</span><br><span class="line">-h  文件大小友好显示</span><br><span class="line">-l  只显示本地文件系统</span><br><span class="line">-i  显示inode信息</span><br><span class="line">-T  显示文件系统类型</span><br></pre></td></tr></table></figure>
</li>
<li><p>du [选项] [文件] | 显示每个文件和目录的磁盘使用空间</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-h  方便阅读的方式</span><br><span class="line">-s  只显示总和的大小</span><br></pre></td></tr></table></figure>
</li>
<li><p>ln [参数] [源文件或目录] [目标文件或目录] | 某一个文件在另外一个位置建立一个同步的链接</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">-s  建立软连接   </span><br><span class="line">-v  显示详细的处理过程</span><br></pre></td></tr></table></figure>
</li>
<li><p>diff [参数] [文件1或目录1] [文件2或目录2] | 比较单个文件或者目录内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-b 　不检查空格字符的不同。</span><br><span class="line">-B 　不检查空白行。</span><br><span class="line">-i  不检查大小写</span><br><span class="line">-q  仅显示差异而不显示详细信息</span><br><span class="line">eg: diff a b &gt; parch.log 比较两个文件的不同并产生补丁</span><br></pre></td></tr></table></figure>
</li>
<li><p>date [参数]… [+格式] | 显示或设定系统的日期与时间</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">%</span><span class="bash">H 小时(以00-23来表示)。 </span></span><br><span class="line"><span class="meta">%</span><span class="bash">M 分钟(以00-59来表示)。 </span></span><br><span class="line"><span class="meta">%</span><span class="bash">P AM或PM。</span></span><br><span class="line"><span class="meta">%</span><span class="bash">D 日期(含年月日)</span></span><br><span class="line"><span class="meta">%</span><span class="bash">U 该年中的周数。</span></span><br><span class="line">date -s “2015-10-17 01:01:01″ //时间设定</span><br><span class="line">date +%Y%m%d         //显示前天年月日</span><br><span class="line">date +%Y%m%d --date="+1 day/month/year"  //显示前一天/月/年的日期</span><br><span class="line">date +%Y%m%d --date="-1 day/month/year"  //显示后一天/月/年的日期</span><br><span class="line">date -d '2 weeks' 2周后的日期</span><br></pre></td></tr></table></figure>
</li>
<li><p>cal [参数] 月份] [年份] | 查看日历</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-1  显示当月的月历</span><br><span class="line">-3  显示前、当、后一个月的日历</span><br><span class="line">-m  显示星期一为一个星期的第一天</span><br><span class="line">-s  （默认）星期天为第一天</span><br><span class="line">-j  显示当月是一年中的第几天的日历</span><br><span class="line">-y  显示当前年份的日历</span><br></pre></td></tr></table></figure>
</li>
<li><p>ps | 列出当前进程的快照</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">a   显示所有的进程</span><br><span class="line">-a  显示同一终端下的所有程序</span><br><span class="line">e   显示环境变量</span><br><span class="line">f   显示进程间的关系</span><br><span class="line">-H  显示树状结构</span><br><span class="line">r   显示当前终端的程序</span><br><span class="line">T   显示当前终端的所有程序</span><br><span class="line">-au 显示更详细的信息</span><br><span class="line">-aux    显示所有包含其他使用者的行程 </span><br><span class="line">-u  指定用户的所有进程</span><br></pre></td></tr></table></figure>
</li>
<li><p>top [参数] | 显示当前系统正在执行的进程的相关信息，包括进程ID、内存占用率、CPU占用率等</p>
</li>
<li>kill [参数] [进程号] | 杀死进程</li>
<li>free [参数] | 显示linux系统中空闲的、已用的物理内存及swap内存,及被内核使用的buffer</li>
<li>vmstat | 对操作系统的虚拟内存、进程、CPU活动进行监控</li>
<li><p>iostat [参数] [时间t] [次数n](每隔t时间刷新一次，最多刷新n次）| 对系统的磁盘操作活动进行监视,汇报磁盘活动统计情况，同时也会汇报出CPU使用情况</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-p[磁盘] 显示磁盘和分区的情况</span><br></pre></td></tr></table></figure>
</li>
<li><p>watch [参数] [命令] |重复执行某一命令以观察变化</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-n  时隔多少秒刷新</span><br><span class="line">-d  高亮显示动态变化</span><br></pre></td></tr></table></figure>
</li>
<li><p>at [参数] [时间] | 在一个指定的时间执行一个指定任务，只能执行一次</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">HH:MM[am|pm] + number [minutes|hours|days|weeks] 强制在某年某月某日的某时刻进行该项任务</span><br><span class="line">atq 查看系统未执行的任务</span><br><span class="line">atrm n 删除编号为n的任务</span><br><span class="line">at -c n 显示编号为n的任务的内容</span><br></pre></td></tr></table></figure>
</li>
<li><p>crontab | 定时任务调度</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">file    载入crontab</span><br><span class="line">    -e  编辑某个用户的crontab文件内容</span><br><span class="line">    -l  显示某个用户的crontab文件内容</span><br><span class="line">    -r  删除某个用户的crontab文件</span><br></pre></td></tr></table></figure>
</li>
<li><p>ifconfig [网络设备] [参数] | 查看和配置网络设备</p>
</li>
<li>route | 显示和操作IP路由表</li>
<li><p>ping [参数] [主机名或IP地址] | 测试与目标主机的连通性</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-q  只显示最后的结果</span><br></pre></td></tr></table></figure>
</li>
<li><p>netstat | 显示与IP、TCP、UDP和ICMP协议相关的统计数据</p>
</li>
<li>telnet [参数] [主机] | 用于远程登录，采用明文传送报文，安全性不好</li>
<li><p>rcp [参数] [源文件] [目标文件] | 远程文件拷贝</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">-r  递归复制</span><br><span class="line">-p  保留源文件的属性</span><br><span class="line">usage: rcp –r remote_hostname:remote_dir local_dir</span><br></pre></td></tr></table></figure>
</li>
<li><p>wget [参数] [URL地址] | 直接从网络上下载文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-o FILE 把记录写到FILE文件中    eg : wget -O a.txt URL</span><br><span class="line">wget --limit-rate=300k URL  限速下载</span><br></pre></td></tr></table></figure>
</li>
<li><p>awk</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-F 分隔符  以分隔符分隔内容</span><br><span class="line">&#123;&#125;  要执行的脚本内容 eg:cat /etc/passwd |awk  -F ':'  '&#123;print $1"\t"$7&#125;'</span><br></pre></td></tr></table></figure>
</li>
<li><p>sed 对数据行进行替换、删除、新增、选取等操作</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">a   新增，在新的下一行出现</span><br><span class="line">c   取代，取代 n1,n2 之间的行 eg: sed '1,2c Hi' ab</span><br><span class="line">d   删除</span><br><span class="line">i   插入，在新的上一行出现</span><br></pre></td></tr></table></figure>
</li>
<li><p>paste 合并文件，需确保合并的两文件行数相同</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-d  指定不同于空格或tab键的域分隔符</span><br><span class="line">-s  按行合并，单独一个文件为一行</span><br></pre></td></tr></table></figure>
</li>
<li><p>su [参数] user | 切换登陆</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-l  切换时连同环境变量、工作目录一起改变</span><br><span class="line">-c command  执行command变回原来的使用者</span><br></pre></td></tr></table></figure>
</li>
<li><p>sudo | 以特定用户的权限执行特定命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-l  列出当前用户可执行的命令</span><br><span class="line">-u username#uid 以指定用户执行命令</span><br></pre></td></tr></table></figure>
</li>
<li><p>file | 判断文件类型</p>
</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/31/linux/linux简单命令/" data-id="ckcc5iwpx009fq4uwe9wmxqk6" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-复杂度" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/30/复杂度/" class="article-date">
  <time datetime="2018-05-30T06:39:45.000Z" itemprop="datePublished">2018-05-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/30/复杂度/">算法复杂度</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="算法复杂度"><a href="#算法复杂度" class="headerlink" title="算法复杂度"></a>算法复杂度</h5><ul>
<li>原文地址： <a href="https://www.cnblogs.com/onepixel/articles/7674659.html" target="_blank" rel="noopener">https://www.cnblogs.com/onepixel/articles/7674659.html</a></li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">排序方法</th>
<th style="text-align:center">时间复杂度（平均）</th>
<th style="text-align:center">时间复杂度（最坏）</th>
<th style="text-align:center">时间复杂度（最好）</th>
<th style="text-align:center">空间复杂度</th>
<th style="text-align:center">稳定性</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">插入排序</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n)</td>
<td style="text-align:center">O(1)</td>
<td style="text-align:center">稳定</td>
</tr>
<tr>
<td style="text-align:center">希尔排序</td>
<td style="text-align:center">O(n1.3)</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n)</td>
<td style="text-align:center">O(1)</td>
<td style="text-align:center">不稳定</td>
</tr>
<tr>
<td style="text-align:center">选择排序</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(1)</td>
<td style="text-align:center">不稳定</td>
</tr>
<tr>
<td style="text-align:center">堆排序</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(1)</td>
<td style="text-align:center">不稳定</td>
</tr>
<tr>
<td style="text-align:center">冒泡排序</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(n)</td>
<td style="text-align:center">O(1)</td>
<td style="text-align:center">稳定</td>
</tr>
<tr>
<td style="text-align:center">快速排序</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(n2)</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">不稳定</td>
</tr>
<tr>
<td style="text-align:center">归并排序</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(nlogn)</td>
<td style="text-align:center">O(n)</td>
<td style="text-align:center">稳定</td>
</tr>
</tbody>
</table>
<ul>
<li>演示</li>
</ul>
<h6 id="插入排序"><a href="#插入排序" class="headerlink" title="插入排序"></a>插入排序</h6><p><img src="https://threadv.github.io/GIf/InsertionSort.gif" alt="InsertionSort"></p>
<h6 id="希尔排序"><a href="#希尔排序" class="headerlink" title="希尔排序"></a>希尔排序</h6><p><img src="https://threadv.github.io/GIf/ShellSort.gif" alt="ShellSort"></p>
<h6 id="选择排序"><a href="#选择排序" class="headerlink" title="选择排序"></a>选择排序</h6><p><img src="https://threadv.github.io/GIf/SelectionSort.gif" alt="SelectionSort"></p>
<h6 id="堆排序"><a href="#堆排序" class="headerlink" title="堆排序"></a>堆排序</h6><p><img src="https://threadv.github.io/GIf/HeapSort.gif" alt="HeapSort"></p>
<h6 id="冒泡排序"><a href="#冒泡排序" class="headerlink" title="冒泡排序"></a>冒泡排序</h6><p><img src="https://threadv.github.io/GIf/BubbleSort.gif" alt="BubbleSort"></p>
<h6 id="快速排序"><a href="#快速排序" class="headerlink" title="快速排序"></a>快速排序</h6><p><img src="https://threadv.github.io/GIf/QuickSort.gif" alt="QuickSort"></p>
<h6 id="归并排序"><a href="#归并排序" class="headerlink" title="归并排序"></a>归并排序</h6><p><img src="https://threadv.github.io/GIf/MergingSort.gif" alt="MergingSort"></p>
<h6 id="计数排序"><a href="#计数排序" class="headerlink" title="计数排序"></a>计数排序</h6><p><img src="https://threadv.github.io/GIf/CountingSort.gif" alt="CountingSort"></p>
<h6 id="桶排序"><a href="#桶排序" class="headerlink" title="桶排序"></a>桶排序</h6><p><img src="https://threadv.github.io/GIf/BucketSort.png" alt="BucketSort"></p>
<h6 id="基数排序"><a href="#基数排序" class="headerlink" title="基数排序"></a>基数排序</h6><p><img src="https://threadv.github.io/GIf/RadixSort.gif" alt="RadixSort"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/30/复杂度/" data-id="ckcc5iwlw0044q4uwoa9q9fwq" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Sort/">Sort</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-sort/快速排序(Quicksort)" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/30/sort/快速排序(Quicksort)/" class="article-date">
  <time datetime="2018-05-30T06:39:45.000Z" itemprop="datePublished">2018-05-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/30/sort/快速排序(Quicksort)/">快速排序(Quicksort)</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p><a href="http://www.runoob.com/w3cnote/sort-algorithm-summary.html" target="_blank" rel="noopener">http://www.runoob.com/w3cnote/sort-algorithm-summary.html</a></p>
<table>
<thead>
<tr>
<th>排序算法</th>
<th>时间复杂度</th>
</tr>
</thead>
<tbody>
<tr>
<td>冒泡排序</td>
<td>O(n2)</td>
</tr>
<tr>
<td>选择排序</td>
<td>O(n2)</td>
</tr>
<tr>
<td>插入排序</td>
<td>O(n2)</td>
</tr>
<tr>
<td>希尔排序</td>
<td>O(n1.5)</td>
</tr>
<tr>
<td>快速排序</td>
<td>O(N*logN)</td>
</tr>
<tr>
<td>归并排序</td>
<td>O(N*logN)</td>
</tr>
<tr>
<td>堆排序</td>
<td>O(N*logN)</td>
</tr>
<tr>
<td>基数排序</td>
<td>O(d(n+r))</td>
</tr>
</tbody>
</table>
<h5 id="快速排序-Quicksort"><a href="#快速排序-Quicksort" class="headerlink" title="快速排序(Quicksort)"></a>快速排序(Quicksort)</h5><ul>
<li>基本思想：（分治）</li>
</ul>
<p>先从数列中取出一个数作为key值；<br>将比这个数小的数全部放在它的左边，大于或等于它的数全部放在它的右边；<br>对左右两个小数列重复第二步，直至各区间只有1个数。</p>
<ul>
<li>辅助理解：<a href="https://blog.csdn.net/morewindows/article/details/6684558/" target="_blank" rel="noopener">挖坑填数</a></li>
</ul>
<ol>
<li>初始时 i = 0; j = 9; key=72<br>由于已经将a[0]中的数保存到key中，可以理解成在数组a[0]上挖了个坑，可以将其它数据填充到这来。<br>从j开始向前找一个比key小的数。当j=8，符合条件，a[0] = a[8] ; i++ ; 将a[8]挖出再填到上一个坑a[0]中。<br>这样一个坑a[0]就被搞定了，但又形成了一个新坑a[8]，这怎么办了？简单，再找数字来填a[8]这个坑。<br>这次从i开始向后找一个大于key的数，当i=3，符合条件，a[8] = a[3] ; j– ; 将a[3]挖出再填到上一个坑中。</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">数组：72 - 6 - 57 - 88 - 60 - 42 - 83 - 73 - 48 - 85</span><br><span class="line"> 0   1   2    3    4    5    6    7    8    9</span><br></pre></td></tr></table></figure>
<ol>
<li>此时 i = 3; j = 7; key=72<br>再重复上面的步骤，先从后向前找，再从前向后找。<br>从j开始向前找，当j=5，符合条件，将a[5]挖出填到上一个坑中，a[3] = a[5]; i++;<br>从i开始向后找，当i=5时，由于i==j退出。<br>此时，i = j = 5，而a[5]刚好又是上次挖的坑，因此将key填入a[5]。</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">数组：48 - 6 - 57 - 88 - 60 - 42 - 83 - 73 - 88 - 85</span><br><span class="line"> 0   1   2    3    4    5    6    7    8    9</span><br></pre></td></tr></table></figure>
<ol>
<li>可以看出a[5]前面的数字都小于它，a[5]后面的数字都大于它。因此再对a[0…4]和a[6…9]这二个子区间重复上述步骤就可以了。</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;数组：48 - 6 - 57 - 42 - 60 - 72 - 83 - 73 - 88 - 85</span><br><span class="line"> 0   1   2    3    4    5    6    7    8    9</span><br></pre></td></tr></table></figure>
<ul>
<li><p>平均时间复杂度：O(N*logN)</p>
</li>
<li><p>方式一</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Quick</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">sort</span><span class="params">(<span class="keyword">int</span> arr[], <span class="keyword">int</span> low, <span class="keyword">int</span> high)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">int</span> l = low;</span><br><span class="line">       <span class="keyword">int</span> h = high;</span><br><span class="line">       <span class="keyword">int</span> povit = arr[low];</span><br><span class="line"></span><br><span class="line">       <span class="keyword">while</span> (l &lt; h) &#123;</span><br><span class="line">           <span class="keyword">while</span> (l &lt; h &amp;&amp; arr[h] &gt;= povit)</span><br><span class="line">               h--;</span><br><span class="line">           <span class="keyword">if</span> (l &lt; h) &#123;</span><br><span class="line">               <span class="keyword">int</span> temp = arr[h];</span><br><span class="line">               arr[h] = arr[l];</span><br><span class="line">               arr[l] = temp;</span><br><span class="line">               l++;</span><br><span class="line">           &#125;</span><br><span class="line">           <span class="keyword">while</span> (l &lt; h &amp;&amp; arr[l] &lt;= povit)</span><br><span class="line">               l++;</span><br><span class="line">           <span class="keyword">if</span> (l &lt; h) &#123;</span><br><span class="line">               <span class="keyword">int</span> temp = arr[h];</span><br><span class="line">               arr[h] = arr[l];</span><br><span class="line">               arr[l] = temp;</span><br><span class="line">               h--;</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="comment">//打印</span></span><br><span class="line">       <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">           System.out.print(arr[i]);</span><br><span class="line">       &#125;</span><br><span class="line">       System.out.println();</span><br><span class="line"></span><br><span class="line">       <span class="comment">//       print(arr);</span></span><br><span class="line">       System.out.println(<span class="string">"l="</span> + (l + <span class="number">1</span>) + <span class="string">"h="</span> + (h + <span class="number">1</span>) + <span class="string">"povit="</span> + povit + <span class="string">"\n"</span>);</span><br><span class="line">       <span class="keyword">if</span> (l &gt; low) sort(arr, low, l - <span class="number">1</span>);</span><br><span class="line">       <span class="keyword">if</span> (h &lt; high) sort(arr, l + <span class="number">1</span>, high);</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>方式二 runoob</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span>  &lt;T extends Comparable&lt;? <span class="keyword">super</span> T&gt;&gt; T[] quickSort(T[] targetArr, <span class="keyword">int</span> start, <span class="keyword">int</span> end) &#123;</span><br><span class="line"></span><br><span class="line">      <span class="keyword">int</span> i = start + <span class="number">1</span>;</span><br><span class="line">      <span class="keyword">int</span> j = end;</span><br><span class="line">      T key = targetArr[start];</span><br><span class="line">      <span class="keyword">while</span> (i &lt; j) &#123;</span><br><span class="line">          <span class="comment">/**</span></span><br><span class="line"><span class="comment">           * 按照j--的方向遍历目标数组，直到比key小的值为止</span></span><br><span class="line"><span class="comment">           */</span></span><br><span class="line">          <span class="keyword">while</span> (j &gt; i &amp;&amp; targetArr[j].compareTo(key) &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">              j--;</span><br><span class="line">          &#125;</span><br><span class="line">          <span class="keyword">if</span> (i &lt; j) &#123;</span><br><span class="line">              <span class="comment">/**</span></span><br><span class="line"><span class="comment">               * targetArr[i]已经保存在key中，可将后面的数填入</span></span><br><span class="line"><span class="comment">               */</span></span><br><span class="line">              targetArr[i] = targetArr[j];</span><br><span class="line">              i++;</span><br><span class="line">          &#125;</span><br><span class="line">          <span class="comment">/**</span></span><br><span class="line"><span class="comment">           * 按照i++的方向遍历目标数组，直到比key大的值为止</span></span><br><span class="line"><span class="comment">           */</span></span><br><span class="line">          <span class="keyword">while</span> (i &lt; j &amp;&amp; targetArr[i].compareTo(key) &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">              <span class="comment">/**</span></span><br><span class="line"><span class="comment">               * 此处一定要小于等于零，假设数组之内有一亿个1，0交替出现的话，而key的值又恰巧是1的话，那么这个小于等于的作用就会使下面的if语句少执行一亿次。</span></span><br><span class="line"><span class="comment">               */</span></span><br><span class="line">              i++;</span><br><span class="line">          &#125;</span><br><span class="line">          <span class="keyword">if</span> (i &lt; j) &#123;</span><br><span class="line">              <span class="comment">/**</span></span><br><span class="line"><span class="comment">               * targetArr[j]已保存在targetArr[i]中，可将前面的值填入</span></span><br><span class="line"><span class="comment">               */</span></span><br><span class="line">              targetArr[j] = targetArr[i];</span><br><span class="line">              j--;</span><br><span class="line">          &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="comment">/**</span></span><br><span class="line"><span class="comment">       * 此时i==j</span></span><br><span class="line"><span class="comment">       */</span></span><br><span class="line">      targetArr[i] = key;</span><br><span class="line">      <span class="comment">//递归调用，把key前面的完成排序</span></span><br><span class="line">      <span class="keyword">this</span>.quickSort(targetArr, start, i - <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">      <span class="comment">//递归调用，把key后面的完成排序</span></span><br><span class="line">      <span class="keyword">this</span>.quickSort(targetArr, j + <span class="number">1</span>, end);</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/30/sort/快速排序(Quicksort)/" data-id="ckcc5iwpe008vq4uwy7i023f1" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Sort/">Sort</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-sort/快速排序JavaScript" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/30/sort/快速排序JavaScript/" class="article-date">
  <time datetime="2018-05-30T06:39:45.000Z" itemprop="datePublished">2018-05-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/30/sort/快速排序JavaScript/">快速排序JavaScript</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="快速排序JavaScript"><a href="#快速排序JavaScript" class="headerlink" title="快速排序JavaScript"></a>快速排序JavaScript</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">quickSort</span>(<span class="params">array</span>)</span>&#123;</span><br><span class="line">        <span class="function"><span class="keyword">function</span> <span class="title">sort</span>(<span class="params">prev, numsize</span>)</span>&#123;</span><br><span class="line">            <span class="keyword">var</span> nonius = prev;</span><br><span class="line">            <span class="keyword">var</span> j = numsize <span class="number">-1</span>;</span><br><span class="line">            <span class="keyword">var</span> flag = array[prev];</span><br><span class="line">            <span class="keyword">if</span> ((numsize - prev) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">                <span class="keyword">while</span>(nonius &lt; j)&#123;</span><br><span class="line">                    <span class="keyword">for</span>(; nonius &lt; j; j--)&#123;</span><br><span class="line">                        <span class="keyword">if</span> (array[j] &lt; flag) &#123;</span><br><span class="line">                            array[nonius++] = array[j];　<span class="comment">//a[i] = a[j]; i += 1;</span></span><br><span class="line">                            <span class="keyword">break</span>;</span><br><span class="line">                        &#125;;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">for</span>( ; nonius &lt; j; nonius++)&#123;</span><br><span class="line">                        <span class="keyword">if</span> (array[nonius] &gt; flag)&#123;</span><br><span class="line">                            array[j--] = array[nonius];</span><br><span class="line">                            <span class="keyword">break</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                array[nonius] = flag;</span><br><span class="line">                sort(<span class="number">0</span>, nonius);</span><br><span class="line">                sort(nonius + <span class="number">1</span>, numsize);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        sort(<span class="number">0</span>, array.length);</span><br><span class="line">        <span class="keyword">return</span> array;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/30/sort/快速排序JavaScript/" data-id="ckcc5iwpf008xq4uw0u63czkj" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Sort/">Sort</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-mysql/sql_hibernate查询" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/29/mysql/sql_hibernate查询/" class="article-date">
  <time datetime="2018-05-29T06:05:35.000Z" itemprop="datePublished">2018-05-29</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/29/mysql/sql_hibernate查询/">hql</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="HQL：hibernate查询语言"><a href="#HQL：hibernate查询语言" class="headerlink" title="HQL：hibernate查询语言"></a>HQL：hibernate查询语言</h5><h6 id="from子句"><a href="#from子句" class="headerlink" title="from子句"></a>from子句</h6><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat</span><br></pre></td></tr></table></figure>
<ul>
<li>子句可以同时出现多个类，查询结果是产生一个笛卡尔积或产生跨表的连接。</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Formula as form ,Parameter as param</span><br></pre></td></tr></table></figure>
<h6 id="关联-Association-与连接-Join"><a href="#关联-Association-与连接-Join" class="headerlink" title="关联(Association)与连接(Join)"></a>关联(Association)与连接(Join)</h6><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat </span><br><span class="line">    inner jon cat.mate as mate</span><br><span class="line">    left outer cat.kittens as kitten</span><br></pre></td></tr></table></figure>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat left join cat.mate.kittens as kittens</span><br></pre></td></tr></table></figure>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Formula form full jon form.parameter param</span><br></pre></td></tr></table></figure>
<ul>
<li>inner jon (内连接) </li>
<li>left outer join (左外连接)</li>
<li>right outer join (右外连接)</li>
<li>full join (全连接，不常用)</li>
<li>通过HQL的with关键字，你可以提供额外的join条件</li>
</ul>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat left join cat.kittens as kitten </span><br><span class="line">    with kitten.bodyWeight &gt; 10.0</span><br></pre></td></tr></table></figure>
<p>一个”fetch”连接允许仅仅使用一个选择语句就将相关联的对象或一组值的集合随着他们的父对象的初始化而被初始化，这种方法在使用到集合的情况下尤其有用，对于关联和集合来说，它有效的代替了映射文件中的外联接 与延迟声明（lazy declarations）. </p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat </span><br><span class="line">    inner join fetch cat.mate</span><br><span class="line">    left join fetch cat.kittens</span><br></pre></td></tr></table></figure>
<p>一个fetch连接通常不需要被指定别名, 因为相关联的对象不应当被用在 where 子句 (或其它任何子句)中。同时，相关联的对象 并不在查询的结果中直接返回，但可以通过他们的父对象来访问到他们。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat </span><br><span class="line">    inner join fetch cat.mate</span><br><span class="line">    left join fetch cat.kittens child</span><br><span class="line">    left join fetch child.kittens</span><br></pre></td></tr></table></figure>
<p>如果你使用属性级别的延迟获取（lazy fetching）（这是通过重新编写字节码实现的），可以使用 fetch all properties 来强制Hibernate立即取得那些原本需要延迟加载的属性（在第一个查询中）。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Document fetch all properties order by name</span><br></pre></td></tr></table></figure>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Document doc fetch all properties where lower(doc.name) like '%cats%'</span><br></pre></td></tr></table></figure>
<h6 id="select-子句"><a href="#select-子句" class="headerlink" title="select 子句"></a>select 子句</h6><p>select 子句选择将哪些对象与属性返 回到查询结果集中.<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> mate </span><br><span class="line">    <span class="keyword">from</span> Cat <span class="keyword">as</span> cat</span><br><span class="line">    <span class="keyword">inner</span> jon cat.mate <span class="keyword">as</span> mate</span><br></pre></td></tr></table></figure></p>
<p>可以更简洁的用以下的查询语句表达相同的含义:<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> cat.mate <span class="keyword">from</span> Cat cat</span><br></pre></td></tr></table></figure></p>
<p>查询语句可以返回值为任何类型的属性，包括返回类型为某种组件(Component)的属性:<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> cat.name <span class="keyword">from</span> DomesticCat cat</span><br><span class="line">    <span class="keyword">where</span> cat.name <span class="keyword">like</span> <span class="string">'fri%'</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> cust.name.firstName <span class="keyword">from</span> Customer <span class="keyword">as</span> cust</span><br></pre></td></tr></table></figure>
<p>查询语句可以返回多个对象和（或）属性，存放在Object[]队列中，</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> mother,offspr,mate.name</span><br><span class="line">    <span class="keyword">from</span> DomesticCat <span class="keyword">as</span> mother</span><br><span class="line">    <span class="keyword">inner</span> <span class="keyword">join</span> mother.mate <span class="keyword">as</span> mate</span><br><span class="line">    <span class="keyword">left</span> <span class="keyword">outer</span> <span class="keyword">join</span> mother.kittens <span class="keyword">as</span> offspr</span><br></pre></td></tr></table></figure>
<p>或存放在一个List对象中，<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">new</span> <span class="keyword">list</span>(mother,offspr,mate.name)</span><br><span class="line">    <span class="keyword">from</span> DomesticCat <span class="keyword">as</span> mother</span><br><span class="line">    <span class="keyword">inner</span> <span class="keyword">join</span> mother.mate <span class="keyword">as</span> mate</span><br><span class="line">    <span class="keyword">left</span> <span class="keyword">outer</span> <span class="keyword">join</span> mother.kittens <span class="keyword">as</span> offspr</span><br></pre></td></tr></table></figure></p>
<p>也可能直接返回一个实际的类型安全的Java对象，<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">new</span> Family(mother,mate,offspr)</span><br><span class="line">    <span class="keyword">from</span> DomesticCat <span class="keyword">as</span> mother</span><br><span class="line">    <span class="keyword">join</span> mother.mate <span class="keyword">as</span> mate</span><br><span class="line">    <span class="keyword">left</span> <span class="keyword">join</span> mother.kittens <span class="keyword">as</span> offspr</span><br></pre></td></tr></table></figure></p>
<h6 id="聚集函数"><a href="#聚集函数" class="headerlink" title="聚集函数"></a>聚集函数</h6><p>HQL查询甚至可以返回作用于属性之上的聚集函数的计算结果: </p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">avg</span>(cat.weight),<span class="keyword">sum</span>(cat.weight),<span class="keyword">max</span>(cat.weight),<span class="keyword">count</span>(cat)</span><br><span class="line"><span class="keyword">from</span> Cat cat</span><br></pre></td></tr></table></figure>
<p>受支持的聚集函数如下： </p>
<ul>
<li>avg(…), sum(…), min(…), max(…) </li>
<li>count(*) </li>
<li>count(…), count(distinct …), count(all…)</li>
</ul>
<p>选择子句中使用数学操作符、连接以及经过验证的sql函数：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> cat.weight + <span class="keyword">sum</span>(kitten.weight)</span><br><span class="line">    <span class="keyword">from</span> Cat cat</span><br><span class="line">    <span class="keyword">join</span> cat.kittens kitten</span><br><span class="line">    <span class="keyword">group</span> <span class="keyword">by</span> cat.id,cat.weight</span><br></pre></td></tr></table></figure>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> firstName||<span class="string">' '</span>||<span class="keyword">initial</span>||<span class="string">' '</span>||<span class="keyword">upper</span>(lastName) <span class="keyword">from</span> Person</span><br></pre></td></tr></table></figure>
<p>关键字distinct与all 也可以使用，它们具有与SQL相同的语义.<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">distinct</span> cat.name <span class="keyword">from</span> Cat cat</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">count</span>(<span class="keyword">distinct</span> cat.name), <span class="keyword">count</span>(cat) <span class="keyword">from</span> Cat cat</span><br></pre></td></tr></table></figure></p>
<h6 id="where-子句"><a href="#where-子句" class="headerlink" title="where 子句"></a>where 子句</h6><p>where 子句允许将返回的实例列表的范围缩小。如果没有指定别名，可以使用属性名直接引用属性</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Cat where name = 'Fritz'</span><br></pre></td></tr></table></figure>
<p>如果指派了别名，需要使用完整的属性名：<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">from Cat as cat where cat.name = 'Fritz'</span><br></pre></td></tr></table></figure></p>
<p>返回名为（属性name等于）’Fritz‘ 的Cat 实例<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> foo </span><br><span class="line">    <span class="keyword">from</span> Foo foo ,Bar bar</span><br><span class="line">    <span class="keyword">where</span> foo.startDate = bar.date</span><br></pre></td></tr></table></figure></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/29/mysql/sql_hibernate查询/" data-id="ckcc5iwoy007yq4uwzqr4m3nk" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql/">mysql</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-java/java-io&amp;encode" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/05/26/java/java-io&encode/" class="article-date">
  <time datetime="2018-05-26T06:05:35.000Z" itemprop="datePublished">2018-05-26</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/05/26/java/java-io&encode/">java-io&amp;encode</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h4 id="I-O、Encode"><a href="#I-O、Encode" class="headerlink" title="I/O、Encode"></a>I/O、Encode</h4><p>Reader类是java的I/O中读字符的父类，而InputStream类是读字节的父类，InputStreamReader类就是关联字节到字符的桥梁，负责在I/O过程中读取字节到字符转换，而对具体字节到字符的解码实现是委托StreamDecoder去做。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">graph TD</span><br><span class="line">    A[InputStream]</span><br><span class="line">    B[Charset]</span><br><span class="line">    C[Reader]</span><br><span class="line">    D(StreamEncoder)--&gt;A</span><br><span class="line">    D(StreamEncoder)--&gt;B</span><br><span class="line">    D(StreamEncoder)--&gt;C</span><br><span class="line">    E[InputStreamWriter]--&gt;D</span><br><span class="line">    E --&gt;C</span><br></pre></td></tr></table></figure></p>
<p>Writer类：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">graph TD</span><br><span class="line">    A[OutputStream]</span><br><span class="line">    B[Charset]</span><br><span class="line">    C[Writer]</span><br><span class="line">    D(StreamEncoder)--&gt;A</span><br><span class="line">    D(StreamEncoder)--&gt;B</span><br><span class="line">    D(StreamEncoder)--&gt;C</span><br><span class="line">    E[OutputStreamWriter]--&gt;D</span><br><span class="line">    E --&gt;C</span><br></pre></td></tr></table></figure></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">   String file = <span class="string">"C:\\Users\\shy\\Desktop\\txt.txt"</span>;</span><br><span class="line">        String charset = <span class="string">"utf-8"</span>;</span><br><span class="line">        <span class="comment">//写字符转换成字节流</span></span><br><span class="line">        FileOutputStream outputStream = <span class="keyword">new</span> FileOutputStream(file);</span><br><span class="line">        OutputStreamWriter writer = <span class="keyword">new</span> OutputStreamWriter(outputStream, charset);</span><br><span class="line"></span><br><span class="line">        writer.write(<span class="string">"2234"</span>);</span><br><span class="line">        writer.close();</span><br><span class="line"></span><br><span class="line">        FileInputStream inputStream = <span class="keyword">new</span> FileInputStream(file);</span><br><span class="line">        InputStreamReader reader = <span class="keyword">new</span> InputStreamReader(inputStream,charset);</span><br><span class="line">        StringBuffer buffer = <span class="keyword">new</span> StringBuffer();</span><br><span class="line">        <span class="keyword">int</span> read = reader.read();</span><br><span class="line">        <span class="keyword">char</span>[] buf = <span class="keyword">new</span> <span class="keyword">char</span>[<span class="number">65</span>];</span><br><span class="line">        <span class="keyword">int</span> count =<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span>((count = reader.read(buf))!=-<span class="number">1</span>)&#123;</span><br><span class="line">            StringBuffer append = buffer.append(buf,<span class="number">0</span>,count);</span><br><span class="line">            System.out.println(append);     <span class="comment">//2234</span></span><br><span class="line">        &#125;</span><br><span class="line"><span class="comment">//        System.out.println(read);</span></span><br><span class="line">        reader.close();</span><br></pre></td></tr></table></figure>
<ul>
<li>String类字节转换为字符</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">String s = <span class="string">"this are some chinese string"</span>;</span><br><span class="line">       <span class="keyword">byte</span>[] b = s.getBytes(<span class="number">0</span><span class="string">"utf-8"</span>);</span><br><span class="line">       String n = <span class="keyword">new</span> String(b,<span class="string">"utf-8"</span>);</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/05/26/java/java-io&encode/" data-id="ckcc5iwnz0068q4uwjwazhpes" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java/">java</a></li></ul>

    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/11/">&laquo; zurück</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/10/">10</a><a class="page-number" href="/page/11/">11</a><span class="page-number current">12</span><a class="page-number" href="/page/13/">13</a><a class="page-number" href="/page/14/">14</a><a class="page-number" href="/page/15/">15</a><a class="extend next" rel="next" href="/page/13/">weiter &raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Design-Patterns/">Design Patterns</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Html/">Html</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Http/">Http</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sort/">Sort</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/algorithm/">algorithm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/elasticsearch/">elasticsearch</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/idea/">idea</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jvm/">jvm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logstash/">logstash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/">php</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pytest/">pytest</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/springboot/">springboot</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/util/">util</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wechat/">wechat</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/我的世界/">我的世界</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/消息队列/">消息队列</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/线程/">线程</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Design-Patterns/" style="font-size: 16.36px;">Design Patterns</a> <a href="/tags/Git/" style="font-size: 10px;">Git</a> <a href="/tags/Html/" style="font-size: 10px;">Html</a> <a href="/tags/Http/" style="font-size: 12.73px;">Http</a> <a href="/tags/JavaScript/" style="font-size: 15.45px;">JavaScript</a> <a href="/tags/Sort/" style="font-size: 18.18px;">Sort</a> <a href="/tags/algorithm/" style="font-size: 11.82px;">algorithm</a> <a href="/tags/ali-weixin-pay/" style="font-size: 13.64px;">ali/weixin pay</a> <a href="/tags/docker/" style="font-size: 17.27px;">docker</a> <a href="/tags/elasticsearch/" style="font-size: 10px;">elasticsearch</a> <a href="/tags/go/" style="font-size: 11.82px;">go</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/idea/" style="font-size: 10px;">idea</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/jvm/" style="font-size: 11.82px;">jvm</a> <a href="/tags/linux/" style="font-size: 18.18px;">linux</a> <a href="/tags/logstash/" style="font-size: 12.73px;">logstash</a> <a href="/tags/mysql/" style="font-size: 14.55px;">mysql</a> <a href="/tags/php/" style="font-size: 11.82px;">php</a> <a href="/tags/pytest/" style="font-size: 10px;">pytest</a> <a href="/tags/python/" style="font-size: 13.64px;">python</a> <a href="/tags/springboot/" style="font-size: 17.27px;">springboot</a> <a href="/tags/util/" style="font-size: 19.09px;">util</a> <a href="/tags/vue/" style="font-size: 10px;">vue</a> <a href="/tags/wechat/" style="font-size: 10.91px;">wechat</a> <a href="/tags/我的世界/" style="font-size: 10px;">我的世界</a> <a href="/tags/消息队列/" style="font-size: 10.91px;">消息队列</a> <a href="/tags/线程/" style="font-size: 11.82px;">线程</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/05/">May 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">April 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/03/">March 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/01/">January 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/02/">February 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">January 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">December 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">November 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/10/">October 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">September 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">July 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">June 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/05/">May 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">April 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">March 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">February 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">January 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">December 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/05/17/linux/linux_shell/">linux—shell</a>
          </li>
        
          <li>
            <a href="/2020/05/16/linux/linux_awk_sed/">linux-awk\sed 示例</a>
          </li>
        
          <li>
            <a href="/2020/04/11/linux/linux_bash/">linux—bash</a>
          </li>
        
          <li>
            <a href="/2020/03/29/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/2020/03/16/go基础/">go基础知识</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 vchen<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>